from kivy.uix.widget import Widget
from kivy.properties import ListProperty


class ScreenStack(Widget):
    stack = ListProperty([])

    def add_screen(self, screen):
        self.stack.append(screen)

    def pop_screen(self):
        return self.stack.pop()


class UniqueScreenStack(ScreenStack):

    def add_screen(self, screen):
        self.remove_screen(screen)
        self.stack.append(screen)

    def remove_screen(self, screen):
        while self.stack.count(screen) > 0:
            self.stack.remove(screen)
